package wdc.test;
import fbp.engine.Component;
import fbp.engine.ComponentDescription;
import fbp.engine.InPort;
import fbp.engine.InPorts;
import fbp.engine.InputPort;
import fbp.engine.OutPort;
import fbp.engine.OutputPort;
import fbp.engine.Packet;


@ComponentDescription("Evaluate MAX value from serie")
@OutPort("OUT")
@InPorts({
	@InPort (value = "SERIE"),
	@InPort (value = "SCALE")		
	})

public class TRANSFORM extends Component {


  InputPort seriePort,scalePort;
  OutputPort outport;
  
  @Override
  protected void execute() {
	Packet p = scalePort.receive();
    if (p==null)return;
    double scale = ((Double)p.getContent()).doubleValue(); 
    drop(p);
    p = seriePort.receive();
    for(; p!=null; p = seriePort.receive()){
    	double current = ((Double)p.getContent()).doubleValue();
	    outport.send(create(new Double(current/scale)));
	    drop(p);
    }
  }

  @Override
  protected void openPorts() {
    seriePort = openInput("SERIE");
    scalePort = openInput("SCALE");
    outport = openOutput("OUT");
  }
}
